package com.alen.websocket;

import java.util.concurrent.TimeUnit;

import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;

public final class Config {
    boolean autoReconnect = true;
    long reconnectInterval = 30;

    boolean enablePing = true;
    /**
     * ping间隔（秒）
     */
    long pingInterval = 30;

    TimeUnit reconnectIntervalTimeUnit = TimeUnit.SECONDS;
    boolean showLog = false;
    String logTag = "WebSocketKit";
    SSLSocketFactory sslSocketFactory;
    X509TrustManager trustManager;

    private Config() {
    }


    public static final class Builder {
        private Config config;

        public Builder() {
            config = new Config();
        }

        /**
         * wss support
         *
         * @param sslSocketFactory
         * @param trustManager
         */
        public Builder setSSLSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager) {
            config.sslSocketFactory = sslSocketFactory;
            config.trustManager = trustManager;
            return this;
        }

        public Builder setAutoReconnect(boolean reconnect) {
            config.autoReconnect = reconnect;
            return this;
        }

        /**
         * set reconnect interval
         *
         * @param interval reconncet interval
         * @param timeUnit unit
         * @return
         */
        public Builder setReconnectInterval(long interval, TimeUnit timeUnit) {
            config.reconnectInterval = interval;
            config.reconnectIntervalTimeUnit = timeUnit;
            return this;

        }

        public Builder setEnablePing(boolean enablePing) {
            config.enablePing = enablePing;
            return this;
        }

        public Builder setShowLog(boolean showLog) {
            config.showLog = showLog;
            return this;
        }

        public Builder setShowLog(boolean showLog, String logTag) {
            config.showLog = showLog;
            config.logTag = logTag;
            return this;
        }

        public Config build() {
            return config;
        }
    }
}
